<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">



	<ui:define name="corpoForm">
		


		<h:form id="formBotoesFilial" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarFilial" value="#{rsc.label_criar}"
					rendered="#{p:ifGranted('CRIAR_FILIAL')}" styleClass="botao"
					action="#{manterFilialBean.criarEntidade}" ajax="false"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterFilialBean.preRenderList}" />
		<h:form id="formListFiliais" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">
				<p:panelGrid columns="5">
					<p:outputLabel value="#{rsc.label_nome} " for="acFilial" />

					<p:outputLabel value="#{rsc.label_responsavel} "
						for="acResponsavel" />

					<p:outputLabel value="#{rsc.label_cidade} " for="acCidade" />

					<p:outputLabel value="#{rsc.label_ativo}" for="cmbAtivo" />

					<p:spacer />


					<p:autoComplete id="acFilial" minQueryLength="3"
						value="#{manterFilialBean.filtro.nome}" effect="fade"
						maxResults="7" size="30"
						completeMethod="#{manterFilialBean.autoCompleteNomeFilial}">
						<p:ajax event="change" update="listaFiliais"
							listener="#{manterFilialBean.buscarPorFiltros}" />
					</p:autoComplete>

					<p:autoComplete id="acResponsavel" minQueryLength="3"
						value="#{manterFilialBean.filtro.responsavel}" effect="fade"
						maxResults="7" size="30"
						completeMethod="#{manterFilialBean.autoCompleteNomeUsuario}">
						<p:ajax event="change" update="listaFiliais"
							listener="#{manterFilialBean.buscarPorFiltros}" />
					</p:autoComplete>

					<p:autoComplete id="acCidade" minQueryLength="3"
						value="#{manterFilialBean.filtro.cidade}" effect="fade"
						maxResults="7"
						completeMethod="#{manterFilialBean.autoCompleteNomeCidade}">
						<p:ajax event="change" update="listaFiliais"
							listener="#{manterFilialBean.buscarPorFiltros}" />
					</p:autoComplete>



					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterFilialBean.filtro.ativo}" id="cmbAtivo">
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterFilialBean.status}" var="c"
							itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listaFiliais"
						actionListener="#{manterFilialBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>
			
			<p:watermark value="#{rsc.wm_nomeFilialConsulta}" for="acFilial" />
			<p:watermark value="#{rsc.wm_responsavelFilial}" for="acResponsavel" />
			<p:watermark value="#{rsc.wm_nomeCidade}" for="acCidade" />

			<p:panel id="pnlListaFiliais"
				header="#{rsc.label_filiaisCadastrados}" toggleable="true"
				toggleSpeed="500">

				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="filial" id="listaFiliais" sortMode="multiple"
						widgetVar="listaFiliaisWid" value="#{manterFilialBean.entidades}"
						paginator="true" rows="10"
						paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">

						<p:column headerText="#{rsc.label_codigo}" sortBy="#{filial.id}">
							<p:outputLabel value="#{filial.id}" />
						</p:column>

						<p:column headerText="#{rsc.label_nome}" sortBy="#{filial.nome}">
							<p:outputLabel value="#{filial.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_cidade}"
							sortBy="#{filial.endereco.cidade.nome}">
							<p:outputLabel value="#{filial.endereco.cidade.nome}" />
						</p:column>


						<p:column headerText="#{rsc.label_responsavel}"
							sortBy="#{filial.responsavel.nome}">
							<p:outputLabel value="#{filial.responsavel.nome}" />
						</p:column>

						<p:column headerText="#{rsc.label_ativo}" sortBy="#{filial.ativo}"
							styleClass="centralizado">
							<p:outputLabel value="#{rsc.label_sim}"
								rendered="#{filial.ativo}" />
							<p:outputLabel value="#{rsc.label_nao}"
								rendered="#{!filial.ativo}" />
						</p:column>


						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">

							<p:commandButton update=":habilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_FILIAL') and !filial.ativo}"
								oncomplete="habilitar.show()" icon="ui-icon ui-icon-locked"
								title="#{rsc.label_habilitar}">
								<f:setPropertyActionListener value="#{filial}"
									target="#{manterFilialBean.entidade}" />
							</p:commandButton>

							<p:commandButton update=":desabilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_FILIAL') and filial.ativo}"
								oncomplete="desabilitar.show()" icon="ui-icon ui-icon-unlocked"
								title="#{rsc.label_desabilitar}">
								<f:setPropertyActionListener value="#{filial}"
									target="#{manterFilialBean.entidade}" />
							</p:commandButton>

							<p:commandButton icon="ui-icon ui-icon-pencil"
								rendered="#{p:ifGranted('ALTERAR_FILIAL')}"
								title="#{rsc.label_editar}" ajax="false" action="editarFilial">
								<f:setPropertyActionListener value="#{filial}"
									target="#{manterFilialBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
		</h:form>


		<p:confirmDialog message="#{msg.questionConfirmaHabilitar}"
			appendTo="@(body)" width="250" id="habilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="habilitar">
			<h:form id="habilitarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterFilialBean.habilitar}"
					oncomplete="habilitar.hide()" styleClass="botao"
					update=":formListFiliais:listaFiliais, :growl" />
				<p:commandButton value="#{rsc.label_nao}" onclick="habilitar.hide()"
					styleClass="botao" />
			</h:form>
		</p:confirmDialog>

		<p:confirmDialog message="#{msg.questionConfirmaDesabilitar}"
			appendTo="@(body)" width="250" id="desabilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="desabilitar">
			<h:form id="desabilitarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterFilialBean.desabilitar}"
					oncomplete="desabilitar.hide()" styleClass="botao"
					update=":formListFiliais:listaFiliais, :growl" />
				<p:commandButton value="#{rsc.label_nao}" styleClass="botao"
					onclick="desabilitar.hide()" type="button" />
			</h:form>
		</p:confirmDialog>

	</ui:define>
</ui:composition>

